package com.picture.wallpaper.manager.check.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.picture.wallpaper.core.utils.TypeUtils;
import com.picture.wallpaper.dao.entity.PictureList;
import com.picture.wallpaper.dao.entity.UserLoginWx;
import com.picture.wallpaper.dao.mapper.pictureListMapper;
import com.picture.wallpaper.dao.mapper.userLoginWxMapper;
import com.picture.wallpaper.manager.check.UserShiroCheck;
import com.picture.wallpaper.manager.redis.RedisUtil;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.stereotype.Service;
import com.picture.wallpaper.dao.dto.PictureDownloadDto;
import javax.annotation.Resource;
import java.util.Objects;

@Service
public class UserShiroCheckImpl implements UserShiroCheck {
    @Resource
    private pictureListMapper pictureListMapper;
    @Resource
    private UserLoginWx userLoginWxs;
    @Resource
    private userLoginWxMapper userLoginWxMapper;
    @Resource
    private PictureDownloadDto pictureDownloadDto;
    @Resource
    private TypeUtils typeUtils;
    @Resource
    private RedisUtil redisUtil;

    @Override
    @ApiModelProperty("用户数据库查询检查")
    public UserLoginWx userCheck(String openId) {
        LambdaQueryWrapper<UserLoginWx> loginWxLambdaQueryWrapper=new LambdaQueryWrapper<>();
        loginWxLambdaQueryWrapper.eq(UserLoginWx::getOpenId,openId);
        userLoginWxs=userLoginWxMapper.selectOne(loginWxLambdaQueryWrapper);
        if (Objects.isNull(userLoginWxs)){
            return null;//非空判断
        }
        return userLoginWxs.getUserShiro()?userLoginWxs:null;//如果为拉黑用户直接返回空值
    }

    @Override
    @ApiModelProperty("图片数据库查询检查")
    public PictureList pictureCheck(String pictureName) {
        LambdaQueryWrapper<PictureList> listLambdaQueryWrapper=new LambdaQueryWrapper<>();
        listLambdaQueryWrapper.eq(PictureList::getPictureName,pictureName);
        return  pictureListMapper.selectOne(listLambdaQueryWrapper);
    }

    @Override
    @ApiModelProperty("redis图片查询检查")
    public boolean getPictureForRedisCheck(String key, String pictureName) {
        return redisUtil.hHasKey(key,pictureName);
    }

}
